<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMapAsync"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :beforeSearchCallback="false"
      @beforeSearchCallback="beforeSearchCallback"
      :clearCallBack="clearCallBack"
    >
      <template slot="endSlotOption">
        <amount-range-search label="金额区间" ref="amountRangeSearch"></amount-range-search>
      </template>
    </Ht-search-form>


    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";
import AmountRangeSearch from "@/views/components/AmountSearchInput";
import HtAmountInput from "@/views/components/HtAmountInput";
import { bepsBorrowNostroHdWkQuery } from "@/api/cnaps/beps/baseHandWork/bepsBorrowNostroHdWk";

export default {
  name: "BepsBaleMethodMaintain",
  mixins: [listPageMixin],
  components: { HtAmountInput,AmountRangeSearch },
  data() {
    return {
      // 查询参数
      queryParams: {
        id:undefined,
        cpgdate:undefined,
        cpgdate2:undefined,
        workdate:undefined,
        workdate2:undefined,
        amount:undefined,
        amount2:undefined,
        stpReason:undefined,
      },
      loading: false,
      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["NSTP_REMARKS","SYSTEMCODE",],
      // 列信息
      regConfig: bepsBorrowNostroHdWkQuery,
      tableBindColumns: [
        { prop: 'id',  label: '交易流水号',width:180},
        { prop: 'cpgdate',  label: 'CPG日期', type: 'date',width:120},
        { prop: 'workdate',  label: '工作日期', type: 'date',width:120},
        { prop: 'sysCode',  label: '系统编号', dictCode:'SYSTEMCODE' ,width:120},
        { prop: 'msgType',  label: '报文类型', formatter(row, text, index) {
            return (row["msgType"] === null || row["msgType"] === undefined ? "" : row["msgType"]) + "-" + (row["msgTypeDesc"] === null || row["msgTypeDesc"] === undefined ? "" : row["msgTypeDesc"]);
          } ,width:120},
        { prop: 'bizTypeCode',  label: '业务类型', formatter(row, text, index) {
            return (row["bizTypeCode"] === null || row["bizTypeCode"] === undefined ? "" : row["bizTypeCode"]) + "-" + (row["bizTypeCodeDesc"] === null || row["bizTypeCodeDesc"] === undefined ? "" : row["bizTypeCodeDesc"]);
          },width:120},
        { prop: 'bizCtgyCode',  label: '业务种类', formatter(row, text, index) {
            return (row["bizCtgyCode"] === null || row["bizCtgyCode"] === undefined ? "" : row["bizCtgyCode"]) + "-" + (row["bizCtgyCodeDesc"] === null || row["bizCtgyCodeDesc"] === undefined ? "" : row["bizCtgyCodeDesc"]);
          },width:120},
        { prop: 'amount',  label: '金额', formatter:amountFormatGet,width:120},
        { prop: 'stpReason',  label: 'non-STP原因',width:120},
      ],
      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {

      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {},
    };
  },
  mounted() {
    this.$refs.amountRangeSearch.$on('getAmountRange',this.beforeSearchCallback);

    const formOptions = [
      // 普通搜索
      {
        type: "dates",
        nameObj: {
          startTimeName: "cpgdate",
          endTimeName: "cpgdate2",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG日期开始", "请输入CPG日期结束"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作日期开始", "请输入工作日期结束"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
      {
        type: "input",
        prop: "id",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },
      {
        type: "dict",
        prop: "stpReason",
        dict: "NSTP_REMARKS",
        defaultAttr: {
          size: "small",
          label: "non-STP原因...",
          placeholder: "non-STP原因...",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },


    beforeSearchCallback() {
      // 搜索按钮之前先执行
      this.queryParams.amount1 = this.$refs.amountRangeSearch.getAmount1();
      this.queryParams.amount2 = this.$refs.amountRangeSearch.getAmount2();
    },
    clearCallBack() {
      let that = this;
      return new Promise(function (resolve, reject) {
        that.$refs.amountRangeSearch.clearAmount();
        that.queryParams.amount1 = "";
        that.queryParams.amount2 = "";
      });
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "PVP结算申请信息报文复核明细";
      this.detailForm = row;
      this.open = true;
    },
    //点击审核按钮
    approve: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          pvpSettlementApplyInformationReviewApprvoe(this.detailForm)
            .then((response) => {
              this.loading = true;
              this.msgSuccess("审核成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },

    //点击拒绝按钮
    reject() {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          pvpSettlementApplyInformationReviewReject(this.detailForm)
            .then((response) => {
              this.msgSuccess("拒绝成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
